package cn.south.campus.business.model.vo;

import cn.south.campus.business.model.entity.GoodsCategory;
import cn.south.campus.common.model.vo.BaseVO;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/11/14 10:20
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class GoodsCategoryVo extends BaseVO {
    /**
     * 分类名称
     */
    private String name;

    /**
     * 父级id
     */
    private Long parentId;

    /**
     * 分类层级
     */
    private Integer level;

    /**
     * 排序
     */
    private Integer sort;

    /**
     * 子分类
     */
    private List<GoodsCategoryVo> children;

    public static GoodsCategory convert(GoodsCategoryVo vo) {
        if (vo == null) {
            return null;
        }
        GoodsCategory category = new GoodsCategory();
        category.setId(vo.getId());
        category.setName(vo.getName());
        category.setParentId(vo.getParentId());
        category.setLevel(vo.getLevel());
        category.setSort(vo.getSort());
        return category;
    }

    public static GoodsCategoryVo convert(GoodsCategory category) {
        if (category == null) {
            return null;
        }
        GoodsCategoryVo vo = new GoodsCategoryVo();
        vo.setId(category.getId());
        vo.setName(category.getName());
        vo.setParentId(category.getParentId());
        vo.setLevel(category.getLevel());
        vo.setSort(category.getSort());
        return vo;
    }
}
